<?php
/**
 * Created by PhpStorm.
 * User: M_Calven
 * Date: 2018/4/23
 * Time: 14:41
 */

namespace common\service\logFilter;


use common\service\FilterFieldService;
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
use yii\log\EmailTarget;

class NewEmailTarget extends EmailTarget
{

    /**
     * 重写该方法
     * @return string
     */
    protected function getContextMessage()
    {
        $context = ArrayHelper::filter($GLOBALS, $this->logVars);

        $context = FilterFieldService::filter($context);

        $result = [];
        foreach ($context as $key => $value) {
            $result[] = "\${$key} = " . VarDumper::dumpAsString($value);
        }
        return implode("\n\n", $result);
    }
}